Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
React axios JSON.stringify() use to [Object object] -> "[Object object]"

i'm junior fronted developer, and i want to your help...

below my pages code

  const sendAnotherIp = async () => {
    const domain_format = /^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?/;

    if (domain_format.test(anotherIp)) {
      await axios
        .get(`${process.env.NEXT_PUBLIC_CLIENT_URL}/api/dnslookup`, {
          params: {
            search: anotherIp,
            date: nowTime,
          },
        })
        .then((res) => {
          alert(res.data);
        });
    } else {
      alert("it's wrong domain format");
    }
  };

  console.log(JSON.stringify(data)); -> "[Object object]"

below my api code

import { NextApiRequest, NextApiResponse } from "next";
const sqlite3 = require("sqlite3").verbose();
const dns = require("dns");

interface Iquerys {
  search: string;
  date: string;
}

interface IUrl {
  ip: string;
}

const dnslookup = (request: NextApiRequest, response) => {
  const req = response.req;

  const querys: Iquerys = req.query;

  const searchData = querys.search;
  const dateData = querys.date;


// below my logic
  response.status(200).end(
    `${dns.resolveAny(searchData, function (err: any, addresses: any) {
      return addresses;
    })}`
  );
//

  // db connect
  let db = new sqlite3.Database("./db/my_database.db", (err) => {
    if (err) {
      return console.log(err.message);
    }
    console.log("Connected to database!");
  });

  // db peristalsis
  db.run("INSERT INTO DnsLookup(search, date) VALUES (?, ?)", [searchData, dateData], (err) => {
    if (err) {
      return console.log(err.message);
    }
    console.log("Row was added to the table: ${this.lastID}");
  });
};

export default dnslookup;

my project build in react, next js. I used to JSON.parse() and JSON.stringify() and toString() ... etc but I can't find a way to real data. what's wrong with my code? help me please guys

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I think the server code is the problem. You should wait for the call back to complete then you should send the response.

response.status(200).end(
    `${dns.resolveAny(searchData, function (err: any, addresses: any) {
      return addresses;
    })}`
  );

On the front end code, you should remove await in front of Axios that is not needed.

about 4 years ago · Juan Pablo Isaza Denunciar

0

First declare the headers to be Application/Json

axios.get('m', { headers: { 'Content-Type': 'application/json' } })

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda